package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.GetDetailProductBMSRequest;
import keeto.com.vn.bms.network.response.GetDetailProductBMSResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskGetProductBMS extends AbstractTask {
	
	String ID;
	int Type;

	public TaskGetProductBMS(BMSListener listener, IBMSCore core, String iD,
			int type) {
		super(listener, core);
		ID = iD;
		Type = type;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		GetDetailProductBMSRequest request = new GetDetailProductBMSRequest();
		request.setId(ID);
		request.setType(Type);
		GetDetailProductBMSResponse response = protocol.getDetailBMS(request);
		for (BMSListener mlistener : listener){
			mlistener.finishGetDetailBMSProduct(response.getReturnCode(), response.getDetailBMSProduct());
		}
		
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mlistener : listener){
			mlistener.finishGetDetailBMSProduct(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, null);
		}
	}

}
